package com.example.myapplicationndk.weight;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.example.myapplicationndk.R;

import androidx.annotation.NonNull;

public class PostStationDialog extends Dialog {

    private Context context;
    OnClickListener Listener;

    public PostStationDialog(@NonNull Context context, OnClickListener listener) {
        super(context, 0);
        this.context = context;
        this.Listener = listener;


        Window win = this.getWindow();
        win.setGravity(Gravity.CENTER);   // 这里控制弹出的位置
        win.getDecorView().setPadding(0, 0, 0, 0);
        win.setWindowAnimations(R.style.myDialogStyle); //设置窗口弹出动画
        WindowManager.LayoutParams lp = win.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.gravity = Gravity.BOTTOM;
        this.getWindow().setBackgroundDrawable(null);
        win.setAttributes(lp);

        View view = LayoutInflater.from(context).inflate(R.layout.dialog_post_station, null);
        setContentView(view);
        initView(view);
        setCancelable(true);
        setCanceledOnTouchOutside(true);

    }

    private void initView(View view) {

        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Listener!=null){
                    Listener.onClick(v);
                }
            }
        });


    }

    public interface OnClickListener {
        void onClick(View v);
    }
}
